package com.dcbeida.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.dcbeida.bean.User;

public class SharedPreferencesUtils {
    public final static String SELECTDATE = "airbike";
    public final static String USER = "user";
    public final static String PHONE = "phone";
    public final static String PWD = "pwd";

    public final static String ISHIDDEN = "is_hidden";//是否显示消息标记

    public SharedPreferences sharedpreferences;
    private static SharedPreferencesUtils instance;

    public static SharedPreferencesUtils getInstance(Context mContext) {
        if (instance == null) {
            instance = new SharedPreferencesUtils(mContext);
        }
        return instance;
    }

    public SharedPreferencesUtils(Context mContext) {
        sharedpreferences = mContext.getSharedPreferences(SELECTDATE, 0);
    }


    public String getPhone() {
        return sharedpreferences.getString(PHONE, "");
    }

    public void setPhone(String phone) {
        Editor editor = sharedpreferences.edit();
        editor.putString(PHONE, phone);
        editor.commit();
    }

    public void setUser(User user) {
        Editor editor = sharedpreferences.edit();
        editor.putString("user", GsonUtil.GsonString(user));
        editor.commit();
    }

    public User getUser() {
        String jsUser = sharedpreferences.getString("user", null);
        return GsonUtil.GsonToBean(jsUser, User.class);
    }

    public String getPwd() {
        return sharedpreferences.getString(PWD, "");
    }

    public void setPwd(String pwd) {
        Editor editor = sharedpreferences.edit();
        editor.putString(PWD, pwd);
        editor.commit();
    }


    public void setIsHidden(boolean isHidden) {
        Editor editor = sharedpreferences.edit();
        editor.putBoolean(ISHIDDEN, isHidden);
        editor.commit();

    }

    public boolean getIsHidden() {
        return sharedpreferences.getBoolean(ISHIDDEN, true);
    }

}
